$(function(){

    $('.activity-left-opts span').each(function (index) {
        $(this).click(function () {
            $(this).addClass('selected').siblings().removeClass('selected');
            $('.right-bottom-content .activity-project').eq(index).show().siblings('.activity-project').hide();
            var _type = $(this).data('type');
            _notice.customPage(null, _type);    
        });
    });
    $(document).on("click",".ic-info-title",function(){
        $(this).siblings('.ic-info-content').slideToggle(300);
    });
    $(document).on("mouseenter",".use-wechat",function(){
        if($(this).find("img").length > 0){
            $(this).find("div.ic-hover-qrcode").show();
        }else{
            var _wx_nick = $("#wx_nick").val();
            if(_wx_nick == ''){
                layer.confirm("您尚未绑定微信，请先前往绑定微信",
                        {
                            area:['auto','auto'],
                            skin:'lay-delete',
                            title:false,
                            closeBtn:false,
                            btn: ['去绑定','暂时不']
                        },
                        function (index) {
                            layer.close(index);
                            pageSkip.openMyActivityAccountThird();
                        },
                        function (index) {
                            layer.close(index);
                        } 
                ); 
            }else{
                var _url = $(this).data("url");
                var _id = "uw-"+Date.now().toString() + '_' + Math.ceil(Math.random() * 10000);
                var _useWechat = '<div class="ic-hover-qrcode">'+
                            '<div id="'+_id+'">'+
        //                        '<img class="img100" src="/Public/image/www/erweima.png" alt="">'+
                            '</div>'+
                            '<p style="margin: 20px 0;font-size: 12px">请使用以下绑定的微信进行扫码</p>'+
                            '<div class="ic-hover-wechat">'+
                                '<span class="fa fa-wechat" style="color:#62b900;"></span>'+
                                '<span>&nbsp;</span>'+
                                '<span>' + _wx_nick + '</span>'+
                            '</div>'+
                        '</div>';
                $(this).append(_useWechat);
                qr_code(_id, "http://h5.huodongju.com"+_url);
            }
        }
    });    
    $(document).on("mouseleave",".use-wechat",function(){
        if($(this).find("img").length > 0){
            $(this).find("div.ic-hover-qrcode").hide();
        }
    });      

    
    var index = $(this).index();

    $(".activity-content-" + index).css("display", "block");
    if ($(".activity-content-" + index).find(".activity-pic").length === 0) {

    }
//    _notice.customPage(null, 2);    

});


var _notice = {
    pages:[],
    customPage: function (page, type) {
        page = page || _notice.pages[type];
        var pageId = 1;
        if(page){
            pageId = page.getCurrent();
        }        
        noticeMessageRequest.getList(pageId, type, function(resultData){
            if(page){
                page.setPageCount(resultData.totalpages);
                page.filling(resultData.currpage);
            }
            var data = resultData.rows;
            var timestamp = new Date().getTime()/1000;
//            console.log(type);
            switch (type){
                case 2:
                    $('#notice_activity').html('');
                    if (data != null && data.length > 0) {
                        for (var i = 0; i < data.length; i++) {
                            if (timestamp > parseInt(data[i].stime) && timestamp < parseInt(data[i].etime)) {
                                data[i].ing = 1;
                            }
                            var notice_item = template("notice_item", data[i]);
                            $('#notice_activity').append(notice_item);
                        }
                    } else {
                        $('#notice_activity').append('<img class="no-data-arrow" src="/Public/image/www/newActivity.png" /><div class="no-data-box"><img class="no-data-img" src="/Public/image/www/no-data.png" alt="这是图片" /><p class="no-data-title">这里什么也没有</p></div>');
                    }
                    break;
                case 4:
                    $('#notice_refund').html('');
                    if (data != null && data.length > 0) {
                        for (var i = 0; i < data.length; i++) {
                            data[i].ing = 1;
                            var notice_item = template("notice_item", data[i]);
                            $('#notice_refund').append(notice_item);
                        }
                    } else {
                        $('#notice_refund').append('<img class="no-data-arrow" src="/Public/image/www/newActivity.png" /><div class="no-data-box"><img class="no-data-img" src="/Public/image/www/no-data.png" alt="这是图片" /><p class="no-data-title">这里什么也没有</p></div>');
                    }
                    break;
                case 5:
                    $('#notice_cash').html('');
                    if (data != null && data.length > 0) {
                        for (var i = 0; i < data.length; i++) {
                            var notice_item = template("notice_item", data[i]);
                            $('#notice_cash').append(notice_item);
                        }
                    } else {
                        $('#notice_cash').append('<img class="no-data-arrow" src="/Public/image/www/newActivity.png" /><div class="no-data-box"><img class="no-data-img" src="/Public/image/www/no-data.png" alt="这是图片" /><p class="no-data-title">这里什么也没有</p></div>');
                    }
                    break;
                case 3:
                    $('#notice_message').html('');
                    if (data != null && data.length > 0) {
                        for (var i = 0; i < data.length; i++) {
                            var notice_item = template("notice_item", data[i]);
                            $('#notice_message').append(notice_item);
                        }
                    } else {
                        $('#notice_message').append('<img class="no-data-arrow" src="/Public/image/www/newActivity.png" /><div class="no-data-box"><img class="no-data-img" src="/Public/image/www/no-data.png" alt="这是图片" /><p class="no-data-title">这里什么也没有</p></div>');
                    }
                    break;
                case 1:
                    $('#notice_sys').html('');
                    if (data != null && data.length > 0) {
                        for (var i = 0; i < data.length; i++) {
                            var notice_item = template("notice_item", data[i]);
                            $('#notice_sys').append(notice_item);
                        }
                    } else {
                        $('#notice_sys').append('<img class="no-data-arrow" src="/Public/image/www/newActivity.png" /><div class="no-data-box"><img class="no-data-img" src="/Public/image/www/no-data.png" alt="这是图片" /><p class="no-data-title">这里什么也没有</p></div>');
                    }
                    break;
            }
        });
    }
};    






